$(function(){
	/**
		 * 默认分享出去的数据
		 *
		 */
		function getShareImageUrl(){

			var share_imgurl = "";
			if("" == share_imgurl){
				var shareImgObj = document.getElementsByClassName("shareImgUrl")[0];
				if('undefined' != typeof(shareImgObj)){
					share_imgurl = shareImgObj.src;
				}
			}
			alert(window.shareData.imgUrl)
			return window.shareData.imgUrl || share_imgurl;
		}
		
		document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
			// 发送给好友
			WeixinJSBridge.on('menu:share:appmessage', function (argv) {
				WeixinJSBridge.invoke('sendAppMessage', { 
					"img_url": "http://www.baidu.com/img/bdlogo.png",
					"img_width": "640",
					"img_height": "640",
					"link": "https://open.weixin.qq.com/connect/oauth2/authorize?appid="  + $.appId +  "&redirect_uri=http%3A%2F%2Fwww.zhihuidao.com.cn&response_type=code&scope=snsapi_base&state=" + $.userId + "#wechat_redirect",
					"desc": "分享给好友，哈哈哈",
					"title": "分享给好友"
				}, function (pic) {
					if('send_app_msg:cancel' != pic.err_msg){
						weimobAfterShare("",window.shareData.sendFriendLink,'appmessage');
					}
					alert(pic.err_msg);
				})
			});

			// 分享到朋友圈
			WeixinJSBridge.on('menu:share:timeline', function (argv) {
				WeixinJSBridge.invoke('shareTimeline', {
					"img_url": getShareImageUrl(),
					"img_width": "640",
					"img_height": "640",
					"link": window.shareData.timeLineLink,
					"desc": window.shareData.tContent,
					"title": window.shareData.tTitle
				}, function (pic) {
					if('share_timeline:cancel' != pic.err_msg){
						//如果用户没有取消
						weimobAfterShare("",window.shareData.timeLineLink,'timeline');
					}
					_report('timeline', pic.err_msg);
				});
			});

			// 分享到微博
			WeixinJSBridge.on('menu:share:weibo', function (argv) {
				WeixinJSBridge.invoke('shareWeibo', {
					"content": window.shareData.wContent,
					"url": window.shareData.weiboLink
				}, function (pic) {
					if('share_weibo:cancel' != pic.err_msg){
						weimobAfterShare("",window.shareData.weiboLink,'weibo');
					}
					_report('weibo', pic.err_msg);
				});
			});
		}, false);
		
});

		